package org.scs.carleton.ca.pgdt.core.internal.parser;

import java.util.ArrayList;
import java.util.List;

import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTClause;
import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTProgram;
import org.scs.carleton.ca.pgdt.core.visitor.PrologVisitor;

/**
 * The physical node for a prolog program
 * 
 * @author tessierj
 *
 */
public class ASTProgram extends ASTNode implements IASTProgram {
	private List<IASTClause> clauses;
	
	public ASTProgram(ASTTranslationUnit translationUnit, int type) {
		super(translationUnit, type);
		clauses = new ArrayList<IASTClause>(10);
	}

	@Override
	public List<IASTClause> getClauses() {
		return clauses;
	}
	
	public void addClause(IASTClause clause) {
		clauses.add(clause);
	}
	
	@SuppressWarnings("nls")
	public String toString() {
		return "Program from offsets... " + getStartOffset() + " to " + getEndOffset();
	}
	
	@Override
	public boolean accept(PrologVisitor visitor) {
		boolean visitChildren = visitor.visit(this);
		
		if (visitor.visit(this)) {
			//If the visitor wants to visit this node...
			for (IASTClause node : clauses) {
				node.accept(visitor);
			}
		}
		
		return visitChildren;
	}
}
